package com.person.leetcode.editor.cn;

/**
  * 415.字符串相加
  * 2023-02-14 16:31:04
**/
public class Sequence_0415_AddStrings {
    public static void main(String[] args) {
        Solution solution = new Sequence_0415_AddStrings().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String addStrings(String num1, String num2) {
        int i = num1.length()-1;
        int j = num2.length()-1;
        int add = 0;
        StringBuilder ans = new StringBuilder();
        while(i>=0 || j>=0 || add != 0){
            int x = i>=0?num1.charAt(i)-'0':0;
            int y = j>=0?num2.charAt(j)-'0':0;
            int res = add + y + x;
            ans.append(res%10);
            add = res/10;
            i--;
            j--;
        }
        ans.reverse();
        return ans.toString();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}